<!--#include file="common/header.html"-->
<body>
    <div class="container-fluid larry-wrapper">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <!--头部搜索-->
                <section class="panel panel-padding">
                    <form class="layui-form" action="/education/admin/roleOperator">
                        <input type="hidden" name="_query.roleId" id="rId">
                        <div class="layui-form">
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input class="layui-input" name="_query.keyword" placeholder="关键字">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button lay-submit class="layui-btn" lay-filter="search" id="search">查找</button>
                            </div>
                        </div>
                    </form>
                </section>

                <!--列表-->
                <section class="panel panel-padding">
                    <div id="list" class="layui-form"></div>
                    <div class="text-right" id="page"></div>
                </section>
            </div>
        </div>
    </div>
    <!-- <th width="130"><input type="checkbox" id="checkall" data-name="checkbox" lay-filter="check"
                               lay-skin="primary"> </th> -->
    <script id="list-tpl" type="text/html"
            data-params='{"url":"/education/admin/roleOperator","dataName":"roleOperatorData","pageid":"#page", "method":"post", "data":"", "async":false}'>
        <table id="example" class="layui-table lay-even" data-name="roleOperatorData" data-tplid="list-tpl">
            <thead>
            <tr>
                <th>是否已授权</th>
                <th>需要授权</th>
                <th width="100">模块名称</th>
                <th>权限名称</th>
                <th>权限路径</th>
            </tr>
            </thead>
            <tbody>
            {{# layui.each(d.list, function(index, item){ }}
            <tr>
                <td><input type="checkbox" name="checkbox" value="{{ item.ids}}" lay-filter="filter"
                           {{# if(item.role_op != null) { }} checked='checked' {{# }}}
                           lay-skin="primary"></td>
                <td>{{# if(item.privilegess == 1) { }} 是 {{# } }} </td>
                <td>{{ item.modulenames||'' }}</td>
                <td>{{ item.names ||'' }}</td>
                <td>{{ item.url ||'' }}</td>
            </tr>
            {{# }); }}
            </tbody>
        </table>
    </script>

</body>
<script src="../js/layui/layui.js"></script>
<script type="text/javascript" src="../js/lib/jquery-1.11.2.min.js"></script>
<!--#include file="common/version.html"-->
<script>
    layui.use(['jquery', 'dtable', 'jqdate', 'jqform', 'upload'], function(exports) {
        var $ = layui.jquery,
                list = layui.dtable,
                ajax = layui.ajax,
                laydate = layui.laydate,
                form = layui.jqform,
                oneList = new list();
        $('#rId').val(roleId);
        var p =$('#list-tpl').data('params');
        p.data = '_query.roleId='+roleId;
        $('#list-tpl').data('params', JSON.stringify(p));
        oneList.init('list-tpl');
    });

    layui.use(['form', 'layer'], function(){
        var form = layui.form();
        var layer = layui.layer;
        form.on('checkbox(filter)', function(data){
//            console.log(data.elem.checked); //是否被选中，true或者false
            console.log(data.value); //复选框value值，也可以通过data.elem.value得到
            var url = data.elem.checked ? '/education/admin/roleOperator/add' : '/education/admin/roleOperator/del';
            var ind = layer.load(1);
            $.post(url, {'roleIds':roleId, 'operatorIds': data.value}, function(rs){
                if(rs.code == 200){
                    layer.close(ind);
                    layer.msg('操作成功');
                    $('#search').trigger('click')
                }
            })
        });
    });

    var roleId = getQueryString('roleId');
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }

</script>

</html>